<?php
    /**
     * Created by PhpStorm.
     * User: zgh
     * Date: 2021-07-31
     * Time: 17:09
     */

    namespace app\api\middleware;
    use think\facade\Response;

    class CrossDomainMiddleware
    {
        public function handle($request, \Closure $next)
        {
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Headers: *');
            header('Access-Control-Allow-Methods: *');
            header('Access-Control-Max-Age: 1728000');
            if (strtoupper($request->method()) == "OPTIONS") {
                return Response::create();
            }
            return $next($request);
        }
    }